package com.egene.tw.activity.product;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.egene.tw.R;
import com.egene.tw.base.BaseFragment;
import com.egene.tw.utils.ImageUtil;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.ViewById;

@EFragment(R.layout.fragment_product)
public class ProductFragment extends BaseFragment {
    @ViewById
    LinearLayout llProductRoot;

    LayoutInflater mInflater;

    public ProductFragment() {
        // Required empty public constructor
    }

    @AfterViews
    void initViews(){
        mInflater = LayoutInflater.from(getActivity());
        for(final ProductItems item : ProductItems.values()){
            LinearLayout vr = new LinearLayout(getActivity());
            View view = mInflater.inflate(R.layout.item_product, null);
            ImageView ivHead = (ImageView) view.findViewById(R.id.ivHead);
            TextView tvTitle = (TextView) view.findViewById(R.id.tvTitle);
            TextView tvDesc = (TextView) view.findViewById(R.id.tvDesc);
            TextView btnSingle = (TextView) view.findViewById(R.id.btnSingle);
            TextView btnPackage = (TextView) view.findViewById(R.id.btnPackage);

            ImageUtil.loadImage(getActivity(), ivHead, item.getImage());
//            Picasso.with(getActivity()).load(item.getImage()).into(ivHead);

            tvTitle.setText(item.getTitle());
            tvDesc.setText(item.getContent());
            btnSingle.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(getActivity(), CategoryListActivity_.class);
                    intent.putExtra(CategoryListActivity.ID,item.getIdx());
                    intent.putExtra(CategoryListActivity.NAME,item.getTitle());
                    getActivity().startActivity(intent);
                }
            });
            btnPackage.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(getActivity(), PackageListActivity_.class);
                    intent.putExtra(PackageListActivity_.ID,item.getIdx());
                    intent.putExtra(PackageListActivity_.NAME,item.getTitle());
                    getActivity().startActivity(intent);
                }
            });

            llProductRoot.addView(view);
        }
    }


}
